//
//  BHShareTool.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/10/14.
//

import UIKit

class BHShareTool: NSObject {
    
    static func share_weblink(title: String?,desText: String?,thumImage: Any?,linkUrl: String?,platForm: UMSocialPlatformType) {
         let manager = UMSocialManager.default()
         
         let shareObj = UMSocialMessageObject.init()
         shareObj.title = title
         shareObj.text = desText
     
         var imgPath = thumImage
         if thumImage is String {
         if thumImage as! String  == "bh_app_share_icon" {
                 imgPath = UIImage.init(named: "bh_app_share_icon")
             }
         }
         
         let webObj = UMShareWebpageObject.shareObject(withTitle: title!, descr: desText!, thumImage: imgPath!)
         webObj!.webpageUrl = linkUrl
         shareObj.shareObject = webObj
         
         manager!.share(to: platForm, messageObject: shareObj, currentViewController: BHBaseViewController.currentViewController, completion: {
             (result, error) in
             
             print(error);
         })
     }
    
    static func showShareMenuView(block: @escaping (UMSocialPlatformType) -> Void) {
        let platForms = BHShareTool.getSharePlatFrom()
        UMSocialUIManager.setPreDefinePlatforms(platForms)
        
        UMSocialUIManager.showShareMenuViewInWindow { (platform, userInfo) in
            block(platform);
        }
   }

}

extension BHShareTool {
    static func getSharePlatFrom() -> [NSNumber] {
        if WXApi.isWXAppInstalled() {
            let array = [NSNumber.init(value: UMSocialPlatformType.wechatSession.rawValue),
                         NSNumber.init(value: UMSocialPlatformType.wechatTimeLine.rawValue)]
            return array
        }else {
            return []
        }
    }
    
    
    static func platForms() -> [Int] {
        let manager = UMSocialManager.default()
        if manager!.isInstall(UMSocialPlatformType.wechatSession) {
            return [1,2]
        }else {
            return []
        }
    }
    
}
